<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2008 XBRL International. All Rights Reserved. -->
<?xml-stylesheet type="text/xsl" href="../stylesheets/functionDefinition.xsl"?>
<function
  xmlns="http://xbrl.org/2008/function" 
  xmlns:reg="http://xbrl.org/2008/registry" 
  xmlns:xhtml="http://www.w3.org/1999/xhtml" 
  xmlns:xfi="http://www.xbrl.org/2008/function/instance"
  xmlns:xfie="http://www.xbrl.org/2008/function/instance/error"
  xmlns:xbrli="http://www.xbrl.org/2003/instance" 
  xmlns:xlink="http://www.w3.org/1999/xlink" 
  xmlns:xl="http://www.xbrl.org/2003/XLink"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="
  http://xbrl.org/2008/registry ../schemas/registry.xsd
  http://xbrl.org/2008/function ../schemas/function.xsd
  ">

  <lastUpdated moment="2010-09-09T20:00:00" />

  <owners>
    <reg:owner id="herm">
       <reg:name>Herm Fischer</reg:name>
      <reg:affiliation>UBMatrix / Mark V Systems</reg:affiliation>
       <reg:email>fischer@markv.com</reg:email>
       <reg:assumedOwnership moment="2009-11-04T20:00:00" />
    </reg:owner>
  </owners>

  <summary>
    Returns a sequence of relationship parents that represent non-abstract concepts and have non-abstract children.
  </summary>

  <documentation>
    This functionality arose from discussions with Victor Morilla on an easy way to check the A = B  + C type of check where A is a parent (from) in a relationship and B and C are child (to) ends of relationships from A.  It is desired to fall back if either A, B, or C are missing.  The usual strategy for this test requires presence of the A or parent fact.  This function allows summation with optional A (parent) facts.  See 61100 test case variation v-09.
      </documentation>

  <signature name="xfi:distinct-nonAbstract-parent-concepts">

    <input name="linkrole" type="xs:string?">
      <xhtml:p>
        The linkrole value that specifies the network of effective
        relationships.
      </xhtml:p>
      <xhtml:p>
        If omitted ("()" or "''") then the default link role is used. 
      </xhtml:p>
    </input>

    <input name="arcrole" type="xs:string">
      <xhtml:p>
        The arcrole value that specifies the network of effective
        relationships.
      </xhtml:p>
    </input>

    <input name="xbrlinstance" type="element(xbrli:xbrl)">
      <xhtml:p>
        This parameter is optional.  If absent the target XBRL instance provides the DTS for linkbases containing
        the specified arcrole. 
        If provided then the specified XBRL instance provides the DTS for the relationship linkbases.
      </xhtml:p>
    </input>

    <output type="xs:QName*">
      <xhtml:p>
        All relationships from the root in the indicated network are checked for any that have non-abstract from (parent) and to (child).  The set of distinct QNames of parents is returned.
      </xhtml:p>

      <xhtml:p>
        This is a helper function for summing children and checking to parent value, when either the parent, or children, may be missing (falling back).  It is used in conjunction with a conceptRelation filter.
      </xhtml:p>

      <xhtml:p>
      Here is the equivalent XPath expression for this function, in terms of the xfi:concept-relations function:<br/>
      <xhtml:pre>
        distinct-values(
     for $relationship in
          xfi:concept-relationships(
                 QName('http://www.xbrl.org/2008/function/instance','root'),
                 'http://abc.com/role/link1',
                 'http://www.xbrl.org/2003/arcrole/parent-child',
                 'sibling-or-descendant') ,
         $from-concept in xfi:relationship-from-concept($relationship),
         $to-concept in xfi:relationship-to-concept($relationship)
     return (
             if ( xfi:concept-custom-attribute($from-concept, QName("","abstract") or
                  xfi:concept-custom-attribute($to-concept, QName("","abstract"))
             then ()
             else $from-concept)
      )
      </xhtml:pre>
      </xhtml:p>
    </output>
  </signature>

  <conformanceTest xlink:type="simple" xlink:href="90510 xfi.distinct-nonAbstract-parent-concepts testcase.xml"/>

  <revisions>
    <reg:revision on="2009-11-04T20:00:00" by="herm">
      <xhtml:p>
        Created this function definition after discussion with Victor Morilla.
      </xhtml:p>
    </reg:revision>

    <reg:revision on="2009-12-12T00:00:00" by="herm">
      <xhtml:p>
        Clarified the xbrlinstance input.
      </xhtml:p>
    </reg:revision>

    <reg:revision on="2010-09-07T00:00:00" by="herm">
      <xhtml:p>
        Incorporated feedback from Hitoshi Okumura.
        Changed input types to "?" for optional parameter linkrole.
        Added xs:anyURI constructor functions.
      </xhtml:p>
    </reg:revision>

    <reg:revision on="2010-09-09T00:00:00" by="herm">
      <xhtml:p>
        Changed role URIs to strings for cast-less coding and to be similar to fn:QName's $paramURI, an xs:string.
      </xhtml:p>
    </reg:revision>
  </revisions>

</function>
